package com.example.customer.controller;

import com.example.customer.remote.ClientRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    ClientRemote clientRemote;

    @RequestMapping("hello")
    public String getClientHello(@RequestParam String name) {

        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://eureka-client/test/hello?hello=" + name,
                                                                     String.class);
        String body = forEntity.getBody();
        return "this is customer:" + body;
    }

    @RequestMapping("hello2")
    public String getClientHello2(@RequestParam String name) {


        String hello = clientRemote.hello(name);
        return "this is customer2:" + hello;
    }


}
